/**
 * 
 */
package org.cuatrovientos.erp.business;

import java.util.List;

import org.apache.log4j.Logger;
import org.cuatrovientos.erp.dao.SaleDAOInterface;
import org.cuatrovientos.erp.model.Sale;
import org.springframework.beans.factory.annotation.Autowired;

/**
 * @author natalia
 * This class implements SaleBOInterface
 *
 */
public class SaleBO implements SaleBOInterface{

	// Get log4j logger
		private static final Logger logger = Logger.getLogger(SaleBO.class);
		
		@Autowired
	    private SaleDAOInterface saleDAO;
		
	/**
	 * @param int id
	 * @return Sale sale
	 * This method returns a sale selected by it's id
	 */
	@Override
	public Sale selectById(int id) {
		logger.info("selectById: " + id);
		return saleDAO.selectById(id);
	}
	
	/**
	 * @return All the sales we have in the database
	 */
	@Override
	public List<Sale> selectAll() {
		logger.info("selectAll: ");
		return saleDAO.selectAll();
	}
	
	/**
	 * @return The number of sales we have in the database
	 */
	@Override
	public List<Sale> search(String name) {
		logger.info("search : " + name);
		return saleDAO.search(name);
	}
	
	/**
	 * @param int id
	 * This method deletes the sale selected by id
	 */
	@Override
	public void deleteById(int id) {
		logger.info("delete by: " + id + " id");
		saleDAO.deleteById(id);
	}
	
	/**
	 * @param Sale sale
	 * This method insert a sale in the database passed by parameter
	 */
	@Override
	public void insert(Sale sale) {
		logger.info("insert: " + sale);
		saleDAO.insert(sale);
	}
	
	/**
	 * @param Sale sale
	 * This method updates a sale passed by parameter
	 */
	@Override
	public void update(Sale sale) {
		logger.info("update: " + sale);
		saleDAO.update(sale);
	}
	
	/**
	 * @param Sale sale
	 * This method deletes a sale passed by parameter
	 */
	@Override
	public void delete(Sale sale) {
		logger.info("delete: " + sale);
		saleDAO.delete(sale);
	}

}
